# -*- coding: utf-8 -*-

import os
import hashlib
from django.db import models
from django.contrib.auth.models import AbstractUser
from core.models import CoreModel, table_prefix


class Role(CoreModel):
    name = models.CharField(max_length=64, verbose_name="角色名称")
    key = models.CharField(unique=True, max_length=64, verbose_name="权限字符")
    admin = models.BooleanField(default=False, verbose_name="是否为admin")
    DATASCOPE_CHOICES = (
        (0, "仅本人数据权限"),
        (1, "本部门及以下数据权限"),
        (2, "本部门数据权限"),
        (3, "全部数据权限"),
        (4, "自定数据权限"),
    )
    data_scope = models.IntegerField(
        default=0, choices=DATASCOPE_CHOICES, verbose_name="数据权限"
    )
    dept = models.ManyToManyField(
        to="Dept", db_constraint=False, verbose_name="数据权限-关联部门"
    )
    menu = models.ManyToManyField(
        to="Menu", db_constraint=False, verbose_name="关联菜单"
    )
    dept_check_strictly = models.BooleanField(default=True, verbose_name="是否父子联动")
    menu_check_strictly = models.BooleanField(default=True, verbose_name="是否父子联动")
    del_flag = models.CharField(
        null=True, blank=True, max_length=32, verbose_name="删除标记"
    )

    class Meta:
        db_table = table_prefix + "system_role"
        verbose_name = "角色管理"
        verbose_name_plural = verbose_name
        ordering = ("sort",)
